package com.huonan.utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.json.JSONUtil;

import java.io.*;
import java.util.concurrent.ExecutionException;

/**
 * @Description TODO
 * @Author lxp
 * @Date 2022/9/29 下午3:46
 * @Version V1.0
 **/
public class FileUse {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String path = "/Users/lxp/IdeaProjects/Study/MainTest/data/out2/tt.txt";
        /**
         * 换行符：FileUtil.FILE_SEPARATOR；分隔符：FileUtil.getLineSeparator()
         * 追加写文件 FileUtil.appendUtf8String
         */
        FileUtil.appendUtf8String("1" + ":Str" + FileUtil.FILE_SEPARATOR, path);
        FileUtil.appendUtf8String("2" + ":Str" + FileUtil.getLineSeparator(), path);
        String filePath = "/Users/lxp/IdeaProjects/Study/MainTest/data/out2/qingbo-video-kuaishou.com_2023-05-17.txt";
        /**
         * 流式读取文件
         */
        String readLine = null;
        try (BufferedReader reader = FileUtil.getUtf8Reader(filePath)) {
            String fitLine;
            while ((fitLine = reader.readLine()) != null) {
                String _id = JSONUtil.parseObj(fitLine).getStr("_id");
                //String _index = JSONUtil.parseObj(line).getStr("_index");
                File zip = ZipUtil.zip(filePath);
                System.out.println(zip.getName());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        File zip = ZipUtil.zip(filePath, "yyy.zip");
        System.out.println(zip.getName());
    }

}
